#include "categary.h"

Categary::Categary()
{
    this->id = "";
    this->subCategary = new QList<Categary *>();
    this->props = new QMap<QString, QString>();
}



Categary::Categary(const QString &id) :
    id(id)
{
    this->id = id;
    this->subCategary = new QList<Categary *>();
    this->props = new QMap<QString, QString>();
}

Categary::~Categary()
{
    delete subCategary;
    delete props;
}

bool Categary::hasSubCategory()
{
    return this->subCategary->isEmpty();
}

QString Categary::getId()
{
    return this->id;
}

QString Categary::getTitle()
{
    return this->props->value("title");
}

QString Categary::getDescription()
{
    return this->props->value("desc");
}

QString Categary::getSpaceId()
{
    return this->props->value("space_id");
}

QString Categary::getPrivacy()
{
    return this->props->value("privacy");
}

void Categary::addSubCategory(Categary *categary)
{
    this->subCategary->append(categary);
}

void Categary::setProp(const QString &val, Categary::PROPERTY prop)
{
    switch (prop)
    {
    case TITLE:
        this->props->insert("title", val);
        break;
    case DESC:
        this->props->insert("desc", val);
        break;
    case SPACE_ID:
        this->props->insert("space_id", val);
        break;
    case PRIVACY:
        this->props->insert("privacy", val);
        break;
    }
}

void Categary::setId(const QString &id)
{
    this->id = id;
}

void Categary::setTitle(const QString &title)
{
    this->props->insert("title", title);
}

void Categary::setDescription(const QString &desc)
{
    this->props->insert("desc", desc);
}

void Categary::setSpaceId(const QString &spaceId)
{
    this->props->insert("space_id", spaceId);
}

void Categary::setPrivacy(const QString &privacy)
{
    this->props->insert("privacy", privacy);
}

QString Categary::getProp(Categary::PROPERTY prop)
{
    QString val = "";
    switch (prop)
    {
    case TITLE:
        val = this->props->value("title");
        break;
    case DESC:
        val = this->props->value("desc");
        break;
    case SPACE_ID:
        val = this->props->value("space_id");
        break;
    case PRIVACY:
        val = this->props->value("privacy");
        break;
    }
    return val;
}

